package org.farng.mp3.object;

/**
 * <p>
 * Title:
 * </p>
 * 
 * <p>
 * Description:
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2002
 * </p>
 * 
 * <p>
 * Company:
 * </p>
 *
 * @author Eric Farng
 * @version $Revision: 1.7 $
 */
public class ObjectBooleanString extends AbstractMP3Object {
    /**
     * Creates a new ObjectBooleanString object.
     *
     * @param identifier DOCUMENT ME!
     */
    public ObjectBooleanString(String identifier) {
        this.identifier = identifier;
    }

    public ObjectBooleanString(ObjectBooleanString object) {
        super(object);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public int getSize() {
        return 1;
    }

    public boolean equals(Object obj) {
        if (obj instanceof ObjectBooleanString == false) {
            return false;
        }

        return super.equals(obj);
    }

    /**
     * DOCUMENT ME!
     *
     * @param str DOCUMENT ME!
     * @param offset DOCUMENT ME!
     *
     * @throws NullPointerException DOCUMENT ME!
     * @throws IndexOutOfBoundsException DOCUMENT ME!
     */
    public void readString(String str, int offset) {
        if (str == null) {
            throw new NullPointerException("String is null");
        }

        if ((offset < 0) || (offset >= str.length())) {
            throw new IndexOutOfBoundsException("Offset to image string is out of bounds: offset = " + offset + ", string.length()" + str.length());
        }

        char ch = str.charAt(offset);

        value = new Boolean(ch != '0');
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String toString() {
        return "" + value;
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String writeString() {
        if (value == null) {
            // default false
            return "0";
        } else {
            return ((Boolean) value).booleanValue() ? "1" : "0";
        }
    }
}